
package com.kugou.game.sdk.receiver;

import com.kugou.game.sdk.service.MessageService;
import com.kugou.game.sdk.statistics.StatCmd;
import com.kugou.game.sdk.statistics.StaticsManager;
import com.kugou.game.sdk.utils.PushMessageHelper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class PushMessageReceiver extends BroadcastReceiver {

    public static final String ACTION_RECEIVE_PUSHMESSAGE = "com.kugou.game.sdk.receive.pushmessage";

    public static final String ACTION_RECEIVE_NOTIFICATION_CLICK = "com.kugou.game.sdk.receive.notification_click";

    public static final String INTENT_EXTRA_INTENT = "com.kugou.game.sdk.receive.intentextra";

    public static final String INTENT_EXTRA_MESSAGEID = "com.kugou.game.sdk.receive.extra.messageid";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION_RECEIVE_PUSHMESSAGE)) {
            // 拉取json字符串
            String jsonStr = intent.getStringExtra(MessageService.INTENT_MESSAGE_INFO_MOREEXTRA);
            if (jsonStr != null) {
                PushMessageHelper.getInstance(context).handlePushMessage(jsonStr);
            }
        } else if (intent.getAction().equals(ACTION_RECEIVE_NOTIFICATION_CLICK)) {
            int msgid = intent.getIntExtra(INTENT_EXTRA_MESSAGEID, 0);
            Intent mIntent = intent.getParcelableExtra(INTENT_EXTRA_INTENT);
            mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (mIntent.resolveActivity(context.getPackageManager()) != null) {
                context.startActivity(mIntent);
            }
            // 发送统计 - 点击推送消息
            StaticsManager.sendPushMessageStatics(StatCmd.CMD_BI_PUSHMESSAGE_CLICK, msgid);
        }
    }

}
